import request from '@/utils/request'

// 获取维修工列表
export function getWorkerList() {
  return request({
    url: '/worker/managent',
    method: 'get'
  })
}

// 添加维修工
export function addWorker(data: {
  WorkerName: string
  WorkerPhone: string
  WorkerAccount: string
  WorkerPassword: string
}) {
  const formData = new FormData()
  formData.append('WorkerName', data.WorkerName)
  formData.append('WorkerPhone', data.WorkerPhone)
  formData.append('WorkerAccount', data.WorkerAccount)
  formData.append('WorkerPassword', data.WorkerPassword)

  return request({
    url: '/worker/managent',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除维修工
export function deleteWorker(WorkerId: string) {
  return request({
    url: `/worker/managent/${WorkerId}`,
    method: 'delete'
  })
}

// 修改维修工信息
export function updateWorker(data: {
  WorkerId: string
  WorkerName?: string
  WorkerPhone?: string
  WorkerAccount?: string
  WorkerPassword?: string
}) {
  const formData = new FormData()
  formData.append('WorkerId', data.WorkerId)
  if (data.WorkerName) formData.append('WorkerName', data.WorkerName)
  if (data.WorkerPhone) formData.append('WorkerPhone', data.WorkerPhone)
  if (data.WorkerAccount) formData.append('WorkerAccount', data.WorkerAccount)
  if (data.WorkerPassword) formData.append('WorkerPassword', data.WorkerPassword)

  return request({
    url: '/worker/managent',
    method: 'put',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
} 